﻿package net.wangit.dev;

import net.wangit.context.ActionContext;
import net.wangit.framework.expression.LabelExpression;
import net.wangit.util.Checker;

/**
 * 标签显示方式
 * 
 * @author watson Feb 26, 2010
 */
public class LabelRule {

	public static final String ID = "1"; // 编号
	public static final String NAME = "2"; // 名称
	public static final String IDNAME = "12"; // 编号名称
	public static final String NAMEID = "21";// 名称编号

	private LabelRule() {
	}

	public static String getLabel(ActionContext ac, String rule, String id,
			String name) {
		if (LabelRule.ID.equals(rule))
			return id;
		if (LabelRule.NAME.equals(rule))
			return Checker.isEmpty(name) ? id : LabelExpression.resolve(ac,
					name);
		if (LabelRule.IDNAME.equals(rule))
			return (new StringBuilder(String.valueOf(id))).append(" ")
					.append(LabelExpression.resolve(ac, name)).toString();
		if (LabelRule.NAMEID.equals(rule))
			return (new StringBuilder(String.valueOf(LabelExpression.resolve(
					ac, name)))).append(" ").append(id).toString();
		else
			return id;
	}
}
